﻿using ElasticSearch.BLL.Helper;
using ElasticSearch.BLL.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace ElasticSearch.Controllers
{
    [RoutePrefix("api/es")]
    public class ElasticSearchController : ApiController
    {
        /// <summary>
        /// 迁移数据到ES
        /// </summary>
        [Route("saveToEs")]
        public string SaveToElasticsearchPtypecollection()
        {
            return SaveToElasticsearchHelper.SaveToElasticsearchPtypecollection();
        }

        /// <summary>
        /// 指定单个key查询
        /// </summary>
        /// <returns></returns>
        [Route("query")]
        public Elastic<ptypecollectionDto> Query(string keyValue)
        {
            return ElasticSearchHelper.Query("ptypecollections", "ptypecollection", "permitno", keyValue, 0,9);
        }

        /// <summary>
        /// 指定多个key查询
        /// </summary>
        /// <returns></returns>
        [Route("querys")]
        public Elastic<ptypecollectionDto> Querys(string keyValue)
        {
            return ElasticSearchHelper.Querys("ptypecollections", "ptypecollection", "permitno,fullname", keyValue, 0, 9);
        }

        /// <summary>
        /// 不指定key查询
        /// </summary>
        /// <returns></returns>
        [Route("queryNoKey")]
        public Elastic<ptypecollectionDto> QueryNoKey(string keyValue)
        {
            return ElasticSearchHelper.QueryNoKey("ptypecollections", "ptypecollection", keyValue, 0, 9);
        }
    }
}
